package com.bf.electroplating.job;

import com.bf.electroplating.pojo.entity.RainfallOutletSite;
import com.bf.electroplating.service.IRainfallWeatherDataSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 雨排口天气数据同步定时任务
 * 
 * @author system
 * @since 2025-01-11
 */
@Slf4j
@Component
public class RainfallWeatherDataSyncJob {

    @Autowired
    private IRainfallWeatherDataSyncService rainfallWeatherDataSyncService;

    /**
     * 每小时同步一次雨排口天气数据
     * 定时任务：每小时的第10分钟执行
     */
    @Scheduled(cron = "0 10 0 * * ?")
    public void syncRainfallWeatherDataHourly() {
        try {
            log.info("开始执行雨排口天气数据同步定时任务");
            rainfallWeatherDataSyncService.syncAllRainfallWeatherData();
            log.info("雨排口天气数据同步定时任务执行完成");
        } catch (Exception e) {
            log.error("雨排口天气数据同步定时任务执行异常", e);
        }
    }

    @Scheduled(cron = "0 10 * * * ?")
    public void syncAllRainfallWeatherDataThisHour() {
        try {
            log.info("开始执行雨排口天气数据同步定时任务");
            rainfallWeatherDataSyncService.syncAllRainfallWeatherDataThisHour();
            log.info("雨排口天气数据同步定时任务执行完成");
        } catch (Exception e) {
            log.error("雨排口天气数据同步定时任务执行异常", e);
        }
    }

    /**
     * 每天凌晨2点执行一次全量同步
     * 定时任务：每天凌晨2点执行
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void syncRainfallWeatherDataDaily() {
        try {
            log.info("开始执行雨排口天气数据每日全量同步任务");
            rainfallWeatherDataSyncService.syncAllRainfallWeatherData();
            log.info("雨排口天气数据每日全量同步任务执行完成");
        } catch (Exception e) {
            log.error("雨排口天气数据每日全量同步任务执行异常", e);
        }
    }

    /**
     * 每周日凌晨3点执行一次深度同步
     * 定时任务：每周日凌晨3点执行
     */
    @Scheduled(cron = "0 0 3 ? * SUN")
    public void syncRainfallWeatherDataWeekly() {
        try {
            log.info("开始执行雨排口天气数据每周深度同步任务");
            rainfallWeatherDataSyncService.syncAllRainfallWeatherData();
            log.info("雨排口天气数据每周深度同步任务执行完成");
        } catch (Exception e) {
            log.error("雨排口天气数据每周深度同步任务执行异常", e);
        }
    }
}
